function Scroll(){
    this.sid = rand(20);
    this.stop = true;
    this.reset();
    this.bind();
}
var ScrollPrototype = Scroll.prototype;
ScrollPrototype.name = "scroll";
ScrollPrototype.report = function(){
    return extend(
        {
            "log_type": "event"
            // 事件分类，用户行为
            ,"category": "behavior"
            // 分类行为，滚动
            ,"action": "scroll"
        }
        ,this.data
    );
}
ScrollPrototype.bind = function() {
    domEvent.add(window, "scroll", this.handler.bind(this));
}
ScrollPrototype.handler = function(){
    if (this.timer) {
        clearTimeout(this.timer);
    }
    this.stop = false;
    this.data.frequency += 1;
    this.timer = setTimeout(function(){
        var top = document.documentElement.scrollTop || document.body.scrollTop;
        if (top > this.data.top) {
            this.data.top = top;
            this.data.views = Math.ceil(top / window.screen.availHeight);
            this.check();
        }
        this.stop = true;
        this.timer = 0;
    }.bind(this), 500);
}
ScrollPrototype.reset = function() {
    this.timer = 0;
    this.checkTimer = 0;
    this.data = {
        // 位置
        "top": 0
        // 滚动的屏幕
        ,"views": 1
        // 滚动操作次数
        ,"frequency": 0
        // 本次的访问 id
        ,"sid": this.sid
        // 页面地址
        ,"path": window.location.href
    };
}
ScrollPrototype.check = function() {
    if (this.stop) {
        this.checkTimer = 0;
        clientCollect.send("event", null, "scroll");
    } else {
        if (this.checkTimer) {
            clearTimeout(this.checkTimer);
        }
        this.checkTimer = setTimeout(function() {
            this.check();
        }.bind(this), 200);
    }
}
clientCollect.add(Scroll);
